import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class Team implements Iterable<HockeyPlayer>{
	private String teamName;
	private List<HockeyPlayer> roster;

	public Team(String inTeamName) {
		teamName = inTeamName;
		roster = new ArrayList<HockeyPlayer>();
	}

	public String getTeamName() {
		return teamName;
	}

	public void add(HockeyPlayer who) {
		roster.add(who);
	}

	public void addGoal(HockeyPlayer looksLike) {
		int foundPosition = roster.indexOf(looksLike);
		if (foundPosition == -1) {
			return;
		}

		HockeyPlayer toUpdate = roster.get(foundPosition);
		toUpdate.addGoal();
	}
	
	public void remove(HockeyPlayer matchThisOne) {
		roster.remove(matchThisOne);
	}

	public int size() {
		int rosterSays = roster.size();
		return rosterSays;
	}

	public HockeyPlayer get(int position) {
		return roster.get(position);
	}
	
	public Iterator<HockeyPlayer> iterator() {
		Collections.sort(roster);
		Collections.reverse(roster);

		return roster.iterator();
	}

	public int getTotalPoints() {
		
		int total = 0;

		for (HockeyPlayer who : roster) {
			int points = who.getTotalPoints();
			total += points;
		}
		
		return total;
	}
}
